﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SQLite;

namespace MsgSender.models
{
    public class SendHistoryModel : BaseModel<SendHistoryModel>
    {
        /// <summary>
        /// 自增主键
        /// </summary>
        public int ID { get; set; }

        /// <summary>
        /// 用户ID
        /// </summary>
        public string UserID { get; set; }

        /// <summary>
        /// 发送文字索引
        /// </summary>
        public int SendTextIndex { get; set; }

        /// <summary>
        /// 发送文字内容
        /// </summary>
        public string SendText { get; set; }

        /// <summary>
        /// 发送时间
        /// </summary>
        public DateTime SendDate { get; set; }


        public override bool Add()
        {
            try
            {
                SQLiteCommand cmd = new SQLiteCommand();
                cmd.CommandText = @"insert into send_history( user_id,send_text_index,send_text,send_date) values(@UserID,@SendTextIndex,@SendText,@SendDate)";
                cmd.Parameters.AddRange(new[] {//添加参数  
                           new SQLiteParameter("@UserID",UserID),  
                           new SQLiteParameter("@SendTextIndex", SendTextIndex),  
                           new SQLiteParameter("@SendText", SendText),
                           new SQLiteParameter("@SendDate", SendDate)
                       });
                return DBHelper.ExecuteNonQuery(cmd) > 0;
            }
            catch (Exception e)
            {
                _logModel.Error(e);
                return false;
            }
        }

        public override bool Delete()
        {
            try
            {
                SQLiteCommand cmd = new SQLiteCommand();
                cmd.CommandText = @"delete from send_history where user_id=@UserID";
                cmd.Parameters.AddRange(new[] {//添加参数   
                           new SQLiteParameter("@UserID",UserID)
                       });
                return DBHelper.ExecuteNonQuery(cmd) > 0;
            }
            catch (Exception e)
            {
                _logModel.Error(e);
                return false;
            }
        }

        public override bool Update()
        {
            return false;
        }

        public override SendHistoryModel Get()
        {
            return null;
        }

    }
}
